# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:biaobai1_0.py
@Time:2024/8/14 7:35

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

import turtle as tu
import random as ra
import tkinter as tk
import math

def Main():
    tu.setup(1.0, 1.0)
    tu.screensize(1.0, 1.0)    #设置画布大小
    tu.bgcolor('black')  #设置画布颜色
    tu.title("❤")
    t = tu.Pen()
    t.ht()               #隐藏画笔
    words = ["我爱你",
            "I Love You!",
            "永远爱你",
            "你是我年少的欢喜",
            "一生一世一双人",
            "余生我陪你走",
            "陪你到来生",
            "春风十里不如你",
            "三生有幸来日方长",
            "夜很长幸有你",
            "爱你的全部",
            "踏过八荒四海只为你",
            "愿得一人心",
            "众里寻他千百度",
            "顶峰相见",
            "等你下课",
            "往后余生",
            "Missing You!",
            "做我女朋友好么",
            "你已经在我的未来里了",
            "陪你到世界之巅",
            "白头偕老",
            "我喜欢你",
            "好想好想你",
            "想你想你想你",
            "今夜月色真美",
            "你是我的唯一"
             ]
    class Love():    #文案类
        def __init__(self):
            self.x = ra.randint(-1000,1000)   #文案的横坐标
            self.y = ra.randint(-500,500)     #文案的纵坐标
            self.f = ra.uniform(-3,3)   #文案左右移动
            self.speed = ra.uniform(2,5)     #文案移动速度
            self.word = ra.choice(words)  # 文案
            self.color = "#%02x%02x%02x" % (ra.randint(0,255),ra.randint(0,255),ra.randint(0,255))   #文案的颜色

        def draw(self):                #写每个文案
            t.penup()                  #提笔
            t.goto(self.x,self.y)      #随机位置
            t.pendown()                #落笔
            t.color(self.color)        #文案颜色
            t.write(self.word, align="center", font=("Comic Sans MS", 24, "bold"))
        def move(self):                    #文案移动函数
            if self.y <= 500:            #当文案还在画布中时
                self.y += self.speed     #设置上下移动速度
                self.x -= self.speed * math.sin(self.f)    #设置左右移动速度
            else:                        #当文案漂出了画布时，重新生成一个文案
                self.x = ra.randint(-1000,1000)
                self.y = -500
                self.f = ra.uniform(-3.14, 3.14)  # 文案左右移动呈正弦函数
                self.speed = ra.uniform(2, 5)  # 文案移动速度
                self.word = ra.choice(words)  # 文案
                self.color = "#%02x%02x%02x" % (ra.randint(0, 255), ra.randint(0, 255), ra.randint(0, 255))  # 文案的颜色


    class Ball():    #彩球类
        def __init__(self):
            self.r = ra.uniform(2,5)       #彩球的半径
            self.x = ra.randint(-1000,1000)   #彩球的横坐标
            self.y = ra.randint(-500,500)     #彩球的纵坐标
            self.speed = ra.uniform(2,10)     #彩球移动速度
            self.color = "#%02x%02x%02x" % (ra.randint(0,255),ra.randint(0,255),ra.randint(0,255))    #彩球的颜色
            self.outline = 10                #彩球的大小
        def draw(self):                #画每个彩球
            x=self.r                   #彩球的半径
            t.pensize(self.outline)    #彩球的大小
            t.penup()                  #提笔
            t.goto(self.x,self.y)      #随机位置
            t.pendown()                #落笔
            t.color(self.color)        #彩球颜色
            t.begin_fill()
            t.fillcolor(self.color)
            t.circle(x)

        def move(self):                    #彩球移动函数
            if self.y >= -500:            #当彩球还在画布中时
                self.y -= self.speed     #设置上下移动速度
            else:                        #当彩球漂出了画布时，重新生成一个彩球
                self.r = ra.uniform(2,3)
                self.x = ra.randint(-1000,1000)
                self.y = 500
                self.speed = ra.uniform(2,10)
                self.color = "#%02x%02x%02x" % (ra.randint(0,255),ra.randint(0,255),ra.randint(0,255))
                self.outline = 10

    Loves = []            #用列表保存所有文案
    for i in range(595):
        Loves.append(Love())
        Loves.append(Ball())
        Loves.append(Ball())
    while True:           #开始绘制
        tu.tracer(0)
        t.clear()
        for i in range(199):    #66个漂浮的文案
            Loves[i].move()
            Loves[i].draw()
        tu.update()
    tu.mainloop()

# 主函数
if __name__ == '__main__':
    root = tk.Tk()
    root.title('❤')
    root.resizable(0, 0)
    screenwidth = root.winfo_screenwidth()
    screenheight = root.winfo_screenheight()
    widths = 300
    heights = 100
    x = (screenwidth - widths) / 2
    y = (screenheight - heights) / 2 - 66
    root.geometry('%dx%d+%d+%d' % (widths, heights, x, y))  # 设置在屏幕中居中显示
    tk.Label(root, text='亲爱的，做我女朋友好吗？', width=37, font=('宋体', 12)).place(x=0, y=10)


    def OK():  # 同意按钮
        root.destroy()
        Main()  # 同意后显示满屏飘字表白代码


    def NO():  # 拒绝按钮，拒绝不会退出，必须同意才可以退出哦~
        tk.messagebox.showwarning('❤', '再给你一次机会！')


    def closeWindow():
        tk.messagebox.showwarning('❤', '逃避是没有用的哦')


    tk.Button(root, text='好哦', width=5, height=1, command=OK).place(x=80, y=50)
    tk.Button(root, text='不要', width=5, height=1, command=NO).place(x=160, y=50)
    root.protocol('WM_DELETE_WINDOW', closeWindow)  # 绑定退出事件
    root.mainloop()